<html>
<head>
<script type="text/javascript">

// Parse URL Variables
// Function based on code from: http://techfeed.net/blog/index.cfm/2007/2/6/JavaScript-URL-variables
function getURLVar(urlVarName) {
	//divide the URL in half at the '?' 
	var urlHalves = String(document.location).split('?');
	var urlVarValue = '';
	if(urlHalves[1]){
		//load all the name/value pairs into an array 
		var urlVars = urlHalves[1].split('&');
		//loop over the list, and find the specified url variable 
		for(i=0; i<=(urlVars.length); i++){
			if(urlVars[i]){
				//load the name/value pair into an array 
				var urlVarPair = urlVars[i].split('=');
				if (urlVarPair[0] && urlVarPair[0] == urlVarName) {
					//I found a variable that matches, load it's value into the return variable 
					urlVarValue = urlVarPair[1];
				}
				}
		}
	}
	return urlVarValue;   
}

// Get variables needed to build craiglists URLs
var query = getURLVar('clms_query');
var catAbb = getURLVar('clms_catAbb');
var srchType = getURLVar('clms_srchType');
var minAsk = getURLVar('clms_minAsk');
var maxAsk = getURLVar('clms_maxAsk');
var hasPic = getURLVar('clms_hasPic');

// Function that creates tabs needed for craigslist searches
function openWindows() {

	var city_list = localStorage["clms_cities"];
	var cities = city_list.split(',');
	for ( var c=cities.length-1; c>=0; --c ){
		chrome.tabs.create({"url":"http://"+cities[c]+".craigslist.org/search/"+catAbb+"?query="+query+"&srchType="+srchType+"&minAsk="+minAsk+"&maxAsk="+maxAsk+"&hasPic="+hasPic, "selected":true});
	}	
	window.close();
}

</script>
</head>

<body onload="openWindows()"></body>

</html>